/**
 * 
 */
package com.gragra.sampling;
import java.util.Date;
import cern.jet.random.Normal;
import cern.jet.random.engine.MersenneTwister;
/**
 * @author Christoph Teichmann
 * 07.06.2013
 */
public class ThreadedNormalAccess
{
	/**
	 * 
	 */
	public static void enableDateInit()
	{sameInit = false;}
	/**
	 * 
	 * @param val
	 * @return
	 */
	public static double setInit(int val)
	{
		sameInit = true;
		return initNum = val;
	}
	/**
	 * 
	 */
	private static int initNum = 830274723;
	/**
	 * 
	 */
	private static boolean sameInit = false;
	/**
	 * 
	 */
	public ThreadedNormalAccess(int threads)
	{
		engines = new Normal[threads];
		for(int i=0;i<threads;++i)
		{engines[i] = new Normal(0.0,1.0,sameInit ? new MersenneTwister(initNum) : new MersenneTwister(new Date()));}
	}
	/**
	 * 
	 */
	private final Normal[] engines;
	/**
	 * 
	 * @param thread
	 * @return
	 */
	public double nextDouble(int thread)
	{return engines[thread].nextDouble();}
	/**
	 * 
	 * @param thread
	 * @param mean
	 * @param std
	 * @return
	 */
	public double nextDouble(int thread,double mean,double std)
	{return engines[thread].nextDouble(mean, std);}
}